/*layui.use(['element'],function(){		
		var element=layui.element;
		$(document).on("click",".li_item",function(){
			var dataId=$(this).data("id");
			if($("#ifm"+dataId).length>0){
				
			}else{
				var title=$(this).text();
				var url=$(this).data("url");
				element.tabAdd("demo",{
					title:title,
					content:"<iframe src='"+url+"' id='ifm"+dataId+"'></iframe>",
					id:"lid_1"+dataId
				});
				element.tabChange("demo","lid_1"+dataId);
			}
			$(".layui-tab-item iframe").height($(".layui-side-scroll").height()-110);
		});
			$(".layui-tab-item iframe").height($(".layui-side-scroll").height()-110);
		});	*/
		layui.use(['form','element','layer'], function() {
		
		var form=layui.form;
		form.render();
		$(".layui-tab-item iframe").height($(".layui-side-scroll").height() - 110);
		var element = layui.element;
		$(document).on("click", ".li_item", function() {
		//alert(111);
		var dataId = $(this).data("id");
		if($("#ifm" + dataId).length > 0) {
			element.tabChange("demo", "lid_" + dataId);
		} else {
			var title = $(this).text();
			var url = $(this).data("url");
			element.tabAdd("demo", {
				title: title,
				content: "<iframe src='" + url + "' id='ifm" + dataId + "'></iframe>",
				id: "lid_1" + dataId
			});
			element.tabChange("demo", "lid_1" + dataId);
		}
		$(".layui-tab-item iframe").height($(".layui-side-scroll").height() - 110);
	});

	$(".layui-tab-item iframe").height($(".layui-side-scroll").height() - 110);
	function updateName(){
		//将本地存储中的用户名称写进到页面
			$(".userName").text(localStorage.getItem("userName"));
			//如果本地存储的头像不为空，将地址发生改变
			if(localStorage.getItem("headImg")!="null"){
				$(".headImg").attr("src",localStorage.getItem("headImg"));
			}
		}
	//调用修改用户名称函数
		updateName();
		//查找菜单
	function find_myMenu(){
		$.ajax({
			type:"get",
			url:"../base/data/index/findMyMenu.json",
			async:true,
			"beforeSend":function(){
			//幕布
			index=layer.load(1,{
				shade:[0.5,"black"]
				});
			},
			"success":function(result){
				if(result.resultCode==0){
					layer.close(index);
					build_MyMenu(result);
				}else{
					layer.msg("服务器崩溃了，请稍后再试",{
						icon:2,
						time:1000
					});
				}
			},
			"error":function(){
				layer.msg("服务器崩溃了，请稍后再试",{
					icon:2,
					time:1000
				});
			}
		});
	}
	
	//显示菜单
	function build_MyMenu(result){
		
		var firstMenu=result.data.menu_1;
		var secondMenu=result.data.menu_2;
		$.each(firstMenu, function(index,item) {
			var li=$("<li></li>").addClass("layui-nav-item");
			var a=$("<a href='javascript:;' data-id='"+item.code+"' data-url=''><i class='fa fa-cogs' aria-hidden='true'></i>&nbsp;"+item.name+"</a>");
			var dl=$("<dl class='layui-nav-child'></dl>");
			var firstMenu=item.code;
			$.each(secondMenu, function(index,item) {
				if(firstMenu==item.fk_parent_id){
					var dd=$("<dd></dd>");
				    var dd_a=$("<a class='li_item' data-id='"+item.code+"' data-url='"+item.url+"'  ><i class='fa fa-address-book' aria-hidden='true'></i>&nbsp;"+item.name+"</a>");
					dd.append(dd_a);
					dl.append(dd);
				}
			});
			
			li.append(a);
			li.append(dl);
			$(".menu_ul").append(li);
		});
						}  
		
	find_myMenu();
});

